using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;
using SystemFramework.Util;

namespace TF.Access {
	public partial class TF_EventH {
		#region Fields
        private string startDateStr;
		#endregion

        #region public property

        public string StartDateStr
        {
            get
            {
                return startDateStr;
            }
            set
            {
                startDateStr = value;
            }
        }

        #endregion

        public static List<TF_EventH> SelectEventHByKeyword(string keywords, int pageSize, int pageIndex)
        {
            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("TF_SelectEventHByKeyword", keywords, pageSize, pageIndex))
            {
                List<TF_EventH> ehList = new List<TF_EventH>();
                while (dataReader.Read())
                {
                    TF_EventH eh = new TF_EventH();
                    if (dataReader.IsDBNull(0) == false)
                    {
                        eh.Id = dataReader.GetInt32(0);
                    }
                    if (dataReader.IsDBNull(1) == false)
                    {
                        eh.EventTitle = dataReader.GetString(1);
                    }
                    if (dataReader.IsDBNull(2) == false)
                    {
                        eh.PicUrl = dataReader.GetString(2);
                    }
                    if (dataReader.IsDBNull(3) == false)
                    {
                        eh.StartDate = dataReader.GetDateTime(3);
                    }
                    if (dataReader.IsDBNull(4) == false)
                    {
                        eh.AttendCount = dataReader.GetInt32(4);
                    }
                    ehList.Add(eh);
                }
                return ehList;
            }
        }

        public static int SelectEventHByKeywordCount(string keywords)
        {
            return ConvertHelper.GetInt(SqlClientUtility.ExecuteScalar("TF_SelectEventHByKeywordCount", keywords), 0);
        }

        /// <summary>
        /// Deletes a record from the TF_EventH table by its primary key and user Id
        /// </summary>
        public void DeleteAll(int uid)
        {
            SqlClientUtility.ExecuteNonQuery("TF_EventHDeleteAll", id, uid);
        }

        public static List<TF_EventH> SelectAllEventH(int pageSize, int pageIndex, int userId)
        {
            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("TF_SelectAllEventH", pageSize, pageIndex, userId))
            {
                List<TF_EventH> tF_EHList = new List<TF_EventH>();
                while (dataReader.Read())
                {
                    TF_EventH tf_eventH = MakeTF_EventH(dataReader);
                    tF_EHList.Add(tf_eventH);
                }
                return tF_EHList;
            }
        }

        public static List<TF_EventH> SelectEventHByCityId(int cityId, int pageSize, int pageIndex)
        {
            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("TF_SelectEventHByCityId", cityId, pageSize, pageIndex))
            {
                List<TF_EventH> tF_EHList = new List<TF_EventH>();
                while (dataReader.Read())
                {
                    TF_EventH tf_eventH = MakeTF_EventH(dataReader);
                    tF_EHList.Add(tf_eventH);
                }
                return tF_EHList;
            }
        }

        public static List<TF_EventH> SelectEventHByProvinceId(int provinceId, int pageSize, int pageIndex)
        {
            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("TF_SelectEventHByProvinceId", provinceId, pageSize, pageIndex))
            {
                List<TF_EventH> tF_EHList = new List<TF_EventH>();
                while (dataReader.Read())
                {
                    TF_EventH tf_eventH = MakeTF_EventH(dataReader);
                    tF_EHList.Add(tf_eventH);
                }
                return tF_EHList;
            }
        }

        public static List<TF_EventH> SelectEventHByCountryId(int countryId, int pageSize, int pageIndex)
        {
            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("TF_SelectEventHByCountryId", countryId, pageSize, pageIndex))
            {
                List<TF_EventH> tF_EHList = new List<TF_EventH>();
                while (dataReader.Read())
                {
                    TF_EventH tf_eventH = MakeTF_EventH(dataReader);
                    tF_EHList.Add(tf_eventH);
                }
                return tF_EHList;
            }
        }
    }
}
